////////////////////////////////////////////////////////////////////////////////
//  COPYRIGHT (C) 2010 TELECOM DIGITAL MEDIA ("TDMEDIA").
//  ALL RIGHTS RESERVED.
//
//  THIS IS CONFIDENTIAL AND PROPRIETARY INTELLECTUAL PROPERTY OWNED BY AND
//  CREATED ON BEHALF OF TDMEDIA. ANY FORM OF DISTRIBUTION, COPY,
//  MODIFICATION WITHOUT THE WRITTEN CONSENT FROM TDMEDIA IS STRICTLY
//  PROHIBITED.
////////////////////////////////////////////////////////////////////////////////
package cc.telecomdigital.tdstock.activity.groups.monitor;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import cc.telecomdigital.tdstock.CommonDefn;
import cc.telecomdigital.tdstock.ITDLApplication;
import cc.telecomdigital.tdstock.R;
import cc.telecomdigital.tdstock.Framework.UniqueItem.TDStockLog;
import cc.telecomdigital.tdstock.Tools.ActivityGroupController;
import cc.telecomdigital.tdstock.activity.BaseActivity;
import cc.telecomdigital.tdstock.activity.groups.MonitorGroup;
import cc.telecomdigital.tdstock.activity.groups.MoreGroup;

/**
 * 
 * @author haibo
 * 
 *  for stock category;
 *
 */
public class StockSectorActivity extends BaseActivity implements
	OnClickListener
{
	protected static final String	TAG	= StockSectorActivity.class
										.getSimpleName();
	private Button				_toolBtnReturn;
	private Button				_classBtnCustomer;
	private Button				_classBtnInsurance;
	private Button				_classBtnBanking;
	private Button				_classBtnEstate;
	private Button				_classBtnEstateMainland;
	private Button				_classBtnFoodstuffs;
	private Button				_classBtnTransportation;
	private Button				_classBtnFinance;

	private static String		_returnBbtnCaption;

	@Override
	public void onClick(View v)
	{
		// BMP Mode by ouyangzhihui 2011-10-13
		Class<? extends Activity> _cls = PortfolioActivity.class;
		if(((ITDLApplication)getApplicationContext()).getIsBMPMode())
		{
			_cls = BMPPortfolioActivity.class;
		}
		
		switch (v.getId())
		{
			case R.id.more_returnbtn:
			case R.id.class_customer:
				
				_returnBbtnCaption = getResources().getString(R.string.monitor);

				((ITDLApplication) getApplicationContext()).putString(CommonDefn.ACTIVITY_CAME_FROM_KEY, _cls.getSimpleName());
				
				Intent intent = new Intent(getApplicationContext(), _cls);
				intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP| Intent.FLAG_ACTIVITY_NO_USER_ACTION);
				SwitchForwardActivity(_cls, intent);
				break;
			default:
				if (v instanceof Button && v.getTag() != null)
				{
					if (v.getTag().toString().matches(CommonDefn.SECTOR_REG))
					{
						((ITDLApplication) getApplicationContext()).putString(CommonDefn.ACTIVITY_CAME_FROM_KEY, v.getTag().toString());
						_returnBbtnCaption = ((Button) v).getText().toString();
						
						Intent currIntent = new Intent(getApplicationContext(), _cls);
						currIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP| Intent.FLAG_ACTIVITY_NO_USER_ACTION);
						
						SwitchForwardActivity(_cls, currIntent);						
					}
				}
				break;
		}

	}

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.stock_class);
		resetMinHeightOnWorkCenter();
		_toolBtnReturn = (Button) findViewById(R.id.more_returnbtn);
		_toolBtnReturn.setOnClickListener(this);

		_classBtnCustomer = (Button) findViewById(R.id.class_customer);
		_classBtnCustomer.setOnClickListener(this);

		_classBtnInsurance = (Button) findViewById(R.id.class_insurancer);
		_classBtnInsurance.setOnClickListener(this);

		_classBtnBanking = (Button) findViewById(R.id.class_banking);
		_classBtnBanking.setOnClickListener(this);

		_classBtnEstate = (Button) findViewById(R.id.class_estate);
		_classBtnEstate.setOnClickListener(this);

		_classBtnEstateMainland = (Button) findViewById(R.id.class_estate_mainland);
		_classBtnEstateMainland.setOnClickListener(this);

		_classBtnFoodstuffs = (Button) findViewById(R.id.class_foodstuff);
		_classBtnFoodstuffs.setOnClickListener(this);

		_classBtnTransportation = (Button) findViewById(R.id.class_transportation);
		_classBtnTransportation.setOnClickListener(this);

		_classBtnFinance = (Button) findViewById(R.id.class_finance);
		_classBtnFinance.setOnClickListener(this);

	}

	@Override
	protected void onPause()
	{
		// TODO Auto-generated method stub
		super.onPause();
	}

	@Override
	protected void onRestart()
	{
		// TODO Auto-generated method stub
		super.onRestart();
	}

	@Override
	protected void onResume()
	{
		// TODO Auto-generated method stub
		super.onResume();
		//_txt.setText(Html.fromHtml( _content));

		resetReturnBtnCaption();
	}

	private void resetReturnBtnCaption()
	{
		if (_returnBbtnCaption == null)
		{
			_returnBbtnCaption = getResources().getString(R.string.monitor);
		}
		_toolBtnReturn.setText(_returnBbtnCaption);
	}
	

	@Override
	public ActivityGroupController GetActivityGroupController()
	{
		//share the same tab with  more group,
		return MonitorGroup.GetActivityGroupHostControl() == null ?  MoreGroup.GetActivityGroupHostControl() : MonitorGroup.GetActivityGroupHostControl() ;
	}

}
